home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 235 / Issue 235 - September 2007 - DPCS0907DVD.ISO / Extras / NetObjects Fusion / NOF10.exe / data1.cab / FSI / lib / nof / util / logging / Formatter.js < prev    next >
Encoding:
Text File  |  2007-04-11  |  2.8 KB  |  104 lines

  1. /****i* SOURCE_FILE/INFO
  2.   *
  3.   * NAME
  4.   *  Formatter.js
  5.   *
  6.   * USAGE
  7.   *  Part of Netobjects JavaScript Library.
  8.   *
  9.   * COPYRIGHT
  10.   *  Copyright ⌐ 2000-2005 Website Pros, Inc.
  11.   *  All Rights Reserved.
  12.   *
  13.   *  This is an unpublished work protected by Website Pros, Inc.
  14.   *  as a trade secret, and is not to be used or disclosed except as
  15.   *  expressly provided in a written license agreement executed by
  16.   *  you and Website Pros, Inc.
  17.   *
  18.   *      <copyright@websitepros.com>
  19.   *
  20.   * NOTES
  21.   *  JavaScript code.
  22.   *
  23.   *****/
  24.  
  25. if (!IS_isModuleInitialized("IS.NOF.UTIL.LOGGING.Formatter"))
  26. {   
  27.     /****h* NOF_JavaScript_Library/NOF.UTIL.LOGGING.Formatter
  28.         *
  29.         * NAME
  30.         *  NOF.UTIL.LOGGING.Formatter
  31.         *
  32.         * DESCRIPTION
  33.         *  
  34.         * A Formatter instance is used by a Handler to transform a log record 
  35.         * into a string.
  36.         *
  37.         * External dependencies: NOF.TEXT.MessageFomat
  38.         ****/
  39.     
  40.     /**
  41.     * constructor 
  42.     *
  43.     **/     
  44.     function LOGGING_Formatter( ) {
  45.         this.__proto__ = LOGGING_Formatter.prototype;
  46.     }
  47.     {
  48.         var member = LOGGING_Formatter.prototype;    
  49.         member.CLASS_NAME        = "LOGGING.Formatter";
  50.         
  51.         var method = LOGGING_Formatter.prototype;    
  52.         
  53.         /**
  54.         * Format the log record. This method should be considered as abstract,
  55.         * here it just return the source class name, the source method name and 
  56.         * the result of the call to <code>formatMessage</code> method.
  57.         *
  58.         * @param logRecord  the log record object created by the logger
  59.         * @return the string representing the formatted message
  60.         **/    
  61.         method.format = function (/*NOF.UTIL.LOGGING.LogRecord*/ logRecord) { 
  62.             var str = "";
  63.             var scn = logRecord.getSourceClassName();
  64.             var smn = logRecord.getSourceMethodName()
  65.                 if (scn != null) {
  66.                     str += scn + "::";
  67.                 }
  68.                 if (smn != null) {
  69.                     str += smn + " > ";
  70.                 }                    
  71.                 str += this.formatMessage(logRecord); 
  72.             return str;
  73.         }
  74.         
  75.         /**
  76.         * This method does format the log record. 
  77.         * It use, if provided, the record's resource bundle to find the value 
  78.         * corresponding to the key specified by the record's message and use 
  79.         * <code>NOF.TEXT.MessageFomat.format(pattern, parameters)</code>
  80.         * method with record's parameters to get the formatted text.
  81.         *
  82.         * @param logRecord  the log record object created by the logger
  83.         * @return the formatted string 
  84.         **/            
  85.         method.formatMessage = function (/*NOF.UTIL.LOGGING.LogRecord*/ logRecord) { 
  86.             var str = logRecord.getMessage();
  87.             var rb = logRecord.getResourceBundle();
  88.             if (rb != null) {
  89.                 var tmpStr = rb.getProperty(str);                
  90.                 if (tmpStr != null) {
  91.                     str = tmpStr;
  92.                 }
  93.             }
  94.             var params = logRecord.getParameters();
  95.             if ( (str != null) && (params != null) ) {                
  96.                 str = NOF.TEXT.MessageFormat.format(str, params);                
  97.             }
  98.             
  99.             return str;
  100.         }
  101.     }
  102.     
  103.     LOGGING.__proto__.Formatter = LOGGING_Formatter;
  104. }